package com.findviewbydream.evil.helloyouth.Utils.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/****************************************************
 * com.aida.evil.eda.Adapter.a
 * 作者：白雨濃  evil
 * 时间：16-2-16 15:29
 * 邮箱：evilbai@foxmail.com
 * 页面用途：
 ****************************************************/
public abstract class CommonAdapter<T> extends BaseAdapter
{
    /**
     * 数据源
     */
    protected List<T> itemBean_list = null;

    /**
     * 上下文对象
     */
    protected Context context = null;

    /**
     * item布局文件的资源ID
     */
    protected int itemLayoutResId = 0;

    public CommonAdapter(Context context, List<T> itemBean_list, int itemLayoutResId)
    {
        this.context = context;
        this.itemBean_list = itemBean_list;
        this.itemLayoutResId = itemLayoutResId;
    }

    @Override
    public int getCount()
    {
        return itemBean_list.size();
    }

    /**
     * 注意，返回值也要为泛型
     */
    @Override
    public T getItem(int position)
    {
        return itemBean_list.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = ViewHolder.getViewHolder(context, itemLayoutResId, position, convertView, parent);

        convert(viewHolder, getItem(position));

        return viewHolder.getConvertView();
    }

    /**
     * 开发者实现该方法，进行业务处理
     */
    public abstract void convert(ViewHolder viewHolder, T item);

}